package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.PublishKnowledgeType;
import com.isunland.managesystem.entity.PublishKnowledgeType.KnowLedgeTypeDetail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 公文类别
 */
public class PublishKnowledgeTypeDialogFragment extends BaseNetworkDialogFragment {

  protected static final String EXTRA_VALUE =
      "com.isunland.managesystem.ui.PublishKnowledgeTypeDialogFragment";
  protected static int KNOWLEDGE = 0;//知识公文
  protected static int PUBLISH_ANNOUNCE = 1;//企业公告
  protected static int KNOWLEDGE_BASE = 2;//韦加 知识库管理:知识库类别
  private int mtype;//判断是知识公文类别，还是企业公告公文类别

  @Override public void onCreate(Bundle savedInstanceState) {
    mtype = getArguments().getInt(EXTRA_VALUE);
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<>();

    try {

      PublishKnowledgeType type = new Gson().fromJson(arg0, PublishKnowledgeType.class);
      List<KnowLedgeTypeDetail> messageDialogs = type.getKnowledgeKindList();
      if (messageDialogs == null || messageDialogs.size() == 0) {
        return null;
      }
      //			String code=CurrentUser.newInstance(getActivity()).getMemberCode()+"-ZSLB-QYGG";
      //			for (int j = 0; j < messageDialogs.size(); j++) {
      //				if(code.equalsIgnoreCase(messageDialogs.get(j).getCustomAttrs())){
      //					messageDialogs.remove(j);
      //					for (int i = 0; i < messageDialogs.size(); i++) {
      //						list.add(new CustomerDialog(messageDialogs.get(i).getName(), messageDialogs.get(i).getCustomAttrs()));
      //					}
      //				}
      //			}

      for (int i = 0; i < messageDialogs.size(); i++) {
        list.add(new CustomerDialog(messageDialogs.get(i).getName(),
            messageDialogs.get(i).getCustomAttrs()));
      }

      return list;
    } catch (Exception e) {

    }

    return list;
  }

  @Override public String getUrl() {
    if (KNOWLEDGE_BASE == mtype) {
      return ApiConst.URL_KNOWLEDGE_TYPE;
    } else {
      return ApiConst.URL_ANOUNCE_TYPE;
    }
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<>();
    params.put("type", "mobile");
    String memberCode = CurrentUser.newInstance(getActivity()).getMemberCode();
    params.put("memberCode", memberCode);
    if (PUBLISH_ANNOUNCE == mtype) {
      //企业公告公文类别
      params.put("kindCode", memberCode + "-ZSLB-QYGG");
    } else if (KNOWLEDGE == mtype) {
      //知识公文类别
      params.put("kindCode", "");
    } else if (KNOWLEDGE_BASE == mtype) {
      //韦加;知识库类别
      params.put("kindCode", memberCode + "-ZSLB-WBGW");
    }
    params.put("dataStatus", "publish");
    return params;
  }

  public static PublishKnowledgeTypeDialogFragment newInstance(int type) {

    Bundle args = new Bundle();
    args.putInt(EXTRA_VALUE, type);
    PublishKnowledgeTypeDialogFragment fragment = new PublishKnowledgeTypeDialogFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
